import os
import sys
import json
import django
import datetime

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(BASE_DIR)
sys.path.extend([BASE_DIR, ])
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "finance_c2c.settings")

django.setup()
from apps.coffee.models import CouponInfo, GiveRecord
from django.db.models import Count
from core.wchat.mini_base import wechat_client
from django.contrib.auth import get_user_model

UserModel = get_user_model()


# 券管理
def coupon_manager():
    now_time = datetime.datetime.today()
    # 券过期
    print(now_time.strftime("%Y-%m-%d"))
    queryset = CouponInfo.objects.filter(expired=False, used=False, expire_time__lte=now_time)
    queryset.update(
        expired=True
    )
    # 赠出未接收返回
    record_queryset = GiveRecord.objects.filter(status=2, create_time__lte=now_time)
    for i in record_queryset:
        i.update_status_3()



if __name__ == '__main__':
    coupon_manager()
